import Cookies from "js-cookie";
const auth = {
  namespaced: true,
  state: {
    userinfo: JSON.parse(localStorage.getItem("userinfo")) || null,
    loggedIn: Cookies.get("loggedIn") || false
  },
  actions: {
    setUser({ state }, payload) {
      console.log("setUser");
      localStorage.setItem("userinfo", JSON.stringify(payload));
      state.userinfo = payload;
    },
    setLoggedIn({ state }, value) {
      Cookies.set("loggedIn", value);
      state.loggedIn = value;
    },
    clearState({ state }) {
      state.userinfo = null;
      state.loggedIn = false;
      console.log(Cookies);
      Cookies.remove("loggedIn");
    }
  }
};
export default auth;
